package pikes.ecma;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import pikes.ecma.VariableDeclaration;

public class VariableDeclarationTestCase {

	private MockSyntaxTreeVisitor syntaxTreeVisitor = null;

	private StringBuilder appendable = null;

	@Before
	public void setup() {
		appendable = new StringBuilder();
		syntaxTreeVisitor = new MockSyntaxTreeVisitor();
	}

	@Test
	public void printVariableDeclaration() throws Exception {
		VariableDeclaration vd = new VariableDeclaration("url");
		vd.print(appendable);

		Assert.assertEquals("url", appendable.toString());

	}

	@Test
	public void visitVariableDeclaration() throws Exception {
		VariableDeclaration vs = new VariableDeclaration("url");
		vs.visit(syntaxTreeVisitor);

		Assert.assertTrue(syntaxTreeVisitor.identifier.equals("url"));

	}

	@Test
	public void printVariableDeclarationWithAssignmentExpression() throws Exception {
		MockIExpression expression = new MockIExpression();
		VariableDeclaration vd = new VariableDeclaration("url", expression);
		vd.print(appendable);

		Assert.assertEquals("url=", appendable.toString());

	}

	@Test
	public void visitVariableDeclarationWithAssignmentExpression() throws Exception {

		MockIExpression expression = new MockIExpression();
		VariableDeclaration vd = new VariableDeclaration("url", expression);
		vd.visit(syntaxTreeVisitor);

		Assert.assertTrue(syntaxTreeVisitor.identifier.equals("url"));
		Assert.assertTrue(syntaxTreeVisitor.isEqualSign);
		Assert.assertSame(syntaxTreeVisitor, expression.syntaxTreeVisitor);

	}
}
